package com.taobao.txc.springCloud.provide1;

import com.taobao.txc.client.aop.TxcTransactionScaner;
import com.taobao.txc.datasource.cobar.TxcDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

@Configuration
public class Config {
  @Bean(name = "primaryDataSource")
  @Qualifier("primaryDataSource")
  @ConfigurationProperties(prefix = "spring.datasource.primary")
  public com.taobao.txc.datasource.cobar.TxcDataSource primaryDataSource() {
    return new TxcDataSource();
  }

  @Bean(name = "primaryJdbcTemplate")
  public JdbcTemplate primaryJdbcTemplate(
      @Qualifier("primaryDataSource") javax.sql.DataSource dataSource) {
    return new JdbcTemplate(dataSource);
  }

  // 定义声明式事务，要想让事务annotation感知的话，要在这里定义一下
  @Bean(name = "txcScanner")
  //    读取配置文件前缀为aluser的属性值
  //    @ConfigurationProperties(prefix="aluser")
  public TxcTransactionScaner txcTransactionScaner() {
    // xxxx填写txc的逻辑组名
    //        return  new TxcTransactionScaner("xxx");

    //        修改为公网txc
    //         <bean class="com.taobao.txc.client.aop.TxcTransactionScaner">
    //    <constructor-arg value="myapp"/>
    //    <constructor-arg value="txc_test_public.1129361738553704.QD"/>
    //    <constructor-arg value="1" />
    //    <constructor-arg value="https://test-cs-gts.aliyuncs.com" />
    //    </bean>
    return new TxcTransactionScaner(
        "myapp", "txc_test_public.1129361738553704.QD", 1, "https://test-cs-gts.aliyuncs.com");
  }
}
